Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Default Schema to Remote Schema #777

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Set Default Schema to Remote Schema #777

wants to merge 6 commits into from

Conversation

haitham911
Copy link
Collaborator

@haitham911 haitham911 commented Nov 13, 2024

what

if schemas.atmos.manifest empty atmos validate not work work.
if schemas.atmos.manifest empty is set Default Schema to Remote Schema .
default remote url https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json

why

We should set the default schema to the remote atmos schema so that atmos validate work

references

DEV-2727
https://linear.app/cloudposse/issue/DEV-2727/set-default-schema-to-remote-schema
DEV-2720
https://linear.app/cloudposse/issue/DEV-2720/error-if-remote-schema-for-validation-not-set

2024-11-17 14_35_09-Window
2024-11-17 14_42_51-Window

Summary by CodeRabbit

  • New Features

    • Introduced a default URL for the Atmos JSON Schema manifest, ensuring a consistent configuration experience.
  • Improvements

    • Simplified logic for determining the Atmos manifest file path, enhancing error handling and control flow.

@osterman
Copy link
Member

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce a new constant, atmosManifestDefault, which sets a default URL for the Atmos JSON Schema manifest. The ExecuteValidateStacksCmd function now assigns this default to cliConfig.Schemas.Atmos.Manifest if it is not configured. Additionally, the logic in the ValidateStacks function for checking the manifest's existence has been simplified, focusing on the new default value and improving error messaging related to the manifest configuration.

Changes

File Change Summary
internal/exec/validate_stacks.go Added constant atmosManifestDefault for default URL. Modified ExecuteValidateStacksCmd to set default URL if not configured. Simplified logic in ValidateStacks for manifest existence checks.

Assessment against linked issues

Objective Addressed Explanation
Set default schema to remote atmos schema (DEV-2727)
Error if remote schema for validation not set (DEV-2720) The implementation does not include error handling for missing schemas as specified.

Possibly related PRs

Suggested reviewers

  • Gowiem

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 411963c and 4dddaa4.

📒 Files selected for processing (1)
  • internal/exec/validate_stacks.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/exec/validate_stacks.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
internal/exec/validate_stacks.go (2)

89-110: LGTM! Clear and robust schema validation logic

The implementation effectively handles the default schema setting and provides comprehensive error handling. The trace logging helps with debugging, and the error message is informative.

A small enhancement suggestion: Consider adding the default schema URL to the error message to make it clear what URL will be used if none is specified.

Here's the suggested improvement for the error message:

 return fmt.Errorf("the Atmos JSON Schema file '%s' does not exist.\n"+
 			"It can be configured in the 'schemas.atmos.manifest' section in 'atmos.yaml', or provided using the 'ATMOS_SCHEMAS_ATMOS_MANIFEST' "+
 			"ENV variable or '--schemas-atmos-manifest' command line argument.\n"+
 			"The path to the schema file should be an absolute path or a path relative to the 'base_path' setting in 'atmos.yaml'. \n"+
-			"Alternatively, you can specify a schema file using a URL that will be downloaded automatically.",
+			"Alternatively, you can specify a schema file using a URL that will be downloaded automatically.\n"+
+			"If not specified, the default schema URL '%s' will be used.",
-			cliConfig.Schemas.Atmos.Manifest)
+			cliConfig.Schemas.Atmos.Manifest, atmosManifestDefault)

100-103: Consider adding retry mechanism for schema downloads

Network requests to download the schema can fail temporarily. Consider implementing a retry mechanism with exponential backoff for better reliability.

Example implementation using a simple retry loop:

+func downloadWithRetry(client *getter.Client, maxRetries int) error {
+    var err error
+    for i := 0; i < maxRetries; i++ {
+        if err = client.Get(); err == nil {
+            return nil
+        }
+        time.Sleep(time.Second * time.Duration(1<<uint(i)))
+    }
+    return err
+}

 func downloadSchemaFromURL(manifestURL string) (string, error) {
     // ... existing code ...
-    if err = client.Get(); err != nil {
+    if err = downloadWithRetry(client, 3); err != nil {
         return "", fmt.Errorf("failed to download the Atmos JSON Schema file '%s' from the URL '%s': %w", fileName, manifestURL, err)
     }
     return atmosManifestJsonSchemaFilePath, nil
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 74516e6 and 2bed139.

📒 Files selected for processing (1)
  • internal/exec/validate_stacks.go (2 hunks)
🔇 Additional comments (1)
internal/exec/validate_stacks.go (1)

22-23: Consider making the schema version configurable

The hardcoded version 1.0 in the URL might make future schema updates challenging. Consider making the version configurable or using version negotiation.

Let's verify if this schema URL is accessible and returns valid JSON:

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 13, 2024
@osterman osterman added the minor New features that do not break anything label Nov 13, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
internal/exec/validate_stacks.go (1)

105-110: Consider making the error message more concise.

The current error message is quite verbose. Consider restructuring it to be more scannable while maintaining the essential information.

-		return fmt.Errorf("the Atmos JSON Schema file '%s' does not exist.\n"+
-			"It can be configured in the 'schemas.atmos.manifest' section in 'atmos.yaml', or provided using the 'ATMOS_SCHEMAS_ATMOS_MANIFEST' "+
-			"ENV variable or '--schemas-atmos-manifest' command line argument.\n"+
-			"The path to the schema file should be an absolute path or a path relative to the 'base_path' setting in 'atmos.yaml'. \n"+
-			"Alternatively, you can specify a schema file using a URL that will be downloaded automatically.",
+		return fmt.Errorf("Schema file '%s' not found. Configure via:\n"+
+			"1. 'schemas.atmos.manifest' in atmos.yaml\n"+
+			"2. ATMOS_SCHEMAS_ATMOS_MANIFEST env var\n"+
+			"3. --schemas-atmos-manifest flag\n\n"+
+			"Accepts: absolute path, relative to base_path, or URL",
			cliConfig.Schemas.Atmos.Manifest)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 74516e6 and 2bed139.

📒 Files selected for processing (1)
  • internal/exec/validate_stacks.go (2 hunks)
🔇 Additional comments (2)
internal/exec/validate_stacks.go (2)

89-92: LGTM! Default schema assignment is solid.

The implementation gracefully handles empty schema configuration by setting a default and providing clear trace logging.


22-22: LGTM! Let's verify the schema URL accessibility.

The constant declaration is well-named and follows Go conventions.

Let's verify the schema URL is accessible and returns valid JSON:

✅ Verification successful

Schema URL is valid and accessible 🛡️

The default schema URL is properly configured and returns valid JSON. The constant can be safely used as the default schema location for manifest validation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify schema URL accessibility and JSON validity
curl -s -f -L https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json | jq . >/dev/null
if [ $? -eq 0 ]; then
    echo "Schema URL is accessible and returns valid JSON"
else
    echo "Failed to validate schema URL"
fi

Length of output: 218

@osterman
Copy link
Member

@haitham911 please share a screenshot of it working and of the error message

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 15, 2024
@osterman osterman mentioned this pull request Nov 15, 2024
cliConfig.Schemas.Atmos.Manifest)
if cliConfig.Schemas.Atmos.Manifest == "" {
cliConfig.Schemas.Atmos.Manifest = atmosManifestDefault
u.LogInfo(cliConfig, fmt.Sprintf("The Atmos JSON Schema file is not configured. Using the default schema '%s'", atmosManifestDefault))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change to debug level, since it's not important enough to output every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants